package com.huaao.micropolice.root.api;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.huaao.micropolice.common.util.JsonUtil;
import com.huaao.micropolice.core.common.page.Page;
import com.huaao.micropolice.core.model.alert.ApiAlert;
import com.huaao.micropolice.core.model.system.User;
import com.huaao.micropolice.core.service.alert.AlertService;
import com.huaao.micropolice.root.controllers.BaseController;

/**
 * 警情处理的类
 * @author Administrator
 *
 */
@Controller
@RequestMapping("AlertInfo")
public class AlertController extends BaseController {
	
	@Autowired
	private  AlertService alertService;
	
	/**
	 * 根据警情Id获取警情的信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/findAlertInfo.do", method = RequestMethod.GET)
	public ResponseEntity<String>  findAlertInfo(@RequestParam("alertid") String alertid){
		ApiAlert alert=alertService.findAlertInfoToid(alertid);
		if(alert!=null){
			return  super.ajaxModel(JSON,"alertid错误");
		}
		 return  super.ajaxModel(JSON,JsonUtil.toJson(alert));
	}
	
	/**
	 * 根据用户id查询用户警情集合
	 * 
	 * @return
	 */
	/*@RequestMapping(value = "/findAlertInfoListToUser.do", method = RequestMethod.GET)
	public ResponseEntity<String>  findAlertInfoListToAlertid(
			@RequestParam(value="page",required=false) int page,
			@RequestParam(value="now",required=false) int now){
		User user = Context.getCurrentUser();
		Page pages=new Page();
		pages.setPageNum(page);
		pages.setPageSize(now);
		List<ApiAlert> alertlist=alertService.findAlertInfoListTouid(user.getId(),pages);
		 return  super.ajaxModel(JSON,JsonUtil.toJson(alertlist));
	}
	*/
	/**
	 * 根据用户id查询用户警情集合
	 * 
	 * @return
	 */
	@RequestMapping(value = "/findAlertInfoListToUser.do", method = RequestMethod.GET)
	public ResponseEntity<String>  saveAlertInfoToUser(
			@RequestParam(value="location") String  location,
			@RequestParam(value="title") String title,
			@RequestParam(value="description") String description,
			@RequestParam(value="address") String address,
			@RequestParam(value="imgs") String imgs,
			@RequestParam(value="voices") String voices,
			@RequestParam(value="videos") String videos,
			@RequestParam(value="type") Byte type 
			){
		ApiAlert alert=new ApiAlert();
		alert.setAddress(address);
		alert.setLocation(location);
		alert.setDescription(description);
		alert.setTitle(title);
		alert.setImgs(imgs);
		alert.setVoices(voices);
		alert.setVideos(videos);
		alert.setType(type);
		alertService.saveAlertInfoAlert(alert);
		return  super.ajaxModel(JSON,"OK");
	}

}
